//显示表格为空时的数据
function notNull(v) {
    if (v == null || v == undefined || v == "") {
        return "--";
    } else {
        return v;
    }
}
//显示日期

function showdate(d) {

    if (d.elem.checked) {
        $(".layui-hide").show();
    } else {
        $(".layui-hide").hide();
    }
}

//删除数据
function delRow(ele, url, fn) {
    $(ele.split(" ")[0]).on("click", ele.split(" ")[1], function() {
        var id = $(this).attr("uid");
        var index = layer.confirm("<span style='color:indianred'>确认删除？</span>", { icon: 0 }, function() {
            $.ajax({
                url: url,
                type: "post",
                data: {
                    id: id
                },
                dataType: "json",
                beforeSend: function() {
                    loadIndex = layer.load(0);
                },
                success: function(d) {
                    layer.close(loadIndex);
                    layer.close(index);
                    if (d.result == "1") {
                        layer.msg("删除成功！", { icon: 1, time: 2000 });
                        if (fn) {
                            fn();
                        }
                    } else {
                        layer.msg("删除失败！", { icon: 2, time: 2000 });
                    }
                },
                error: function() {
                    layer.close(loadIndex);
                    layer.close(index);
                    layer.msg("网络异常！", { icon: 2, time: 2000 });
                }
            });
        });
    });
}

function changeRow(ele, url, data, fn) {
    $(ele.split(" ")[0]).on("click", ele.split(" ")[1], function() {
        data.id = $(this).attr("uid");
        data.state = $(this).attr("state");
        var index = layer.confirm("<span style='color:indianred'>你确定" + (data.state == 1 ? "停用" : "启用") + "</span>", { icon: 0 }, function() {
            $.ajax({
                url: url,
                type: "post",
                data: data,
                dataType: "json",
                beforeSend: function() {
                    loadIndex = layer.load(0);
                },
                success: function(d) {
                    layer.close(loadIndex);
                    layer.close(index);
                    if (d.result == "1") {
                        layer.msg((data.state == 1 ? "停用" : "启用") + "成功！", { icon: 1, time: 2000 });
                        if (fn) {
                            fn();
                        }
                    } else {
                        layer.msg((data.state == 1 ? "停用" : "启用") + "失败！", { icon: 2, time: 2000 });
                    }
                },
                error: function() {
                    layer.close(loadIndex);
                    layer.close(index);
                    layer.msg("网络异常！", { icon: 2, time: 2000 });
                }
            });
        });
    });
}